import webbrowser

""" Constants for switch statements """
DAYS = {0:"today ", 1:"tomorrow ", 2:"the day after tomorrow ", 3: "in 3 days "}
TIMES = {0:"during the day ", 1:"at night time "}
FILE_NAME = "your_answers.html"

class Display:
    """
    This class acts as a view for the application.
    It is responsible for printing the user requested results to an
    HTML page, and display it.
    """
    
    def __init__(self) :
        self.nextIndex = 1
        self.fp = open(FILE_NAME, "wb")
        self.fp.write("<html>\n\t<head>\n")
        self.fp.write("\t\t<title>Your Europe Quicky Weather Answers</title>\n")
        self.fp.write("\t</head>\n")
        self.fp.write("\t<body bgcolor='navyblue' align='center'>\n")
        self.fp.write("\t\t<h1>Here Are Your Europe Quicky Weather Answers</h1>\n") 
        self.fp.write("\t\t<table border='3' bgcolor='white' cellpadding='4'align='center' width='80%'>\n")
        self.browser = webbrowser.get()
        self.write_suffix()
        
    def wish_weather(self, day, time, min, max, list) :
        self.write_result("In the following cities the temperatures "+DAYS[day] + TIMES[time] + "will be between " + repr(min) + " and " + repr(max) + " degrees:", list)

    def no_rain(self, list):
        self.write_result("In the following cities there will be no rain during the next 3 days:", list)
        
    def cur_weather(self, city, conditions):
        self.write_result("Current weather in " + city + ":", conditions)

    def weather_forecast(self, city, forecast):
        self.write_result("The weather in " + city + " in the next 3 days:", forecast)
         
    def todays_stats(self, stats):
        self.write_result("Today's weather statistics in Europe:", stats)
         
    def write_result(self, header, details):
        self.fp.seek(self.nextAnswer)
        self.fp.write("<pre>\t\t\t<tr>\n</pre>")    
        self.fp.write("<pre>\t\t\t\t<td width='100'> Answer no." + repr(self.nextIndex) + "</td>\n</pre>")           
        self.fp.write("<pre>\t\t\t\t<td><b>"+ header +"</b></br>\n</pre>")
        for detail in details :
            self.fp.write("<pre>\t\t\t\t" + detail + "\n</pre>")
        self.fp.write("<pre>\n\t\t\t\t</td>\n\t\t\t</tr>\n</pre>")   
        self.nextIndex += 1 
        self.write_suffix() 
        self.fp.flush() 
        self.browser.open(self.fp.name, new=2, autoraise=True)
        
    def write_suffix(self):
        self.nextAnswer = self.fp.tell()
        self.fp.write("\t\t</table>\n\t</body>\n</html>")